Creating a gambas2 program, step by step, a telephone index


From : http://listingambas.blogspot.com/2011/06/anexo-4-empaquetadodesempaquetado-de.html


Annex 4: Packing / Unpacking Data

"Houston, Houston, we have a problem"
As we said at the time of saving data, we only save the path to images, not the image itself (well, only the thumbnails are stored
in "listin / mini ")
Normally that is effective, but ... What happens if we change the computer? What we do if  "big" images are on an external hard drive?
Can we make a backup of all data?


Well, to solve these problems,what we can do is:
For this, in the form Fmain we're going to create a new option in the menu, called "Create General List"





With the following code:
PUBLIC SUB GeneraList_Click ()
    import.completed ()
END

Now
we create the procedure completed() in the module import
SUB completed ()
'definition of local variables
DIM a AS Integer
DIM target AS String
DIM sLine AS String
DIM Endofline AS String
DIM NewRecPhoto AS NEW String []

IF Exist ( " ~ / listin / " ) THEN
'Directory exists, no need to create it
ELSE
'Directory doesn't exists, we must create it
    Mkdir " ~ / listin / "
ENDIF

'Create and copy all photos with their original size in file "~/listin/photos"
IF Exist ( "~ / listin / photos" ) THEN
'Directory exists, no need to create it
ELSE
'Directory doesn't exists, we must create it
    Mkdir "~ / listin / photos"
ENDIF
'Begin copy of all photos ...
FOR a = 0 TO var.dni.COUNT - 1
'shell copy command
    IF Exist ( "~ / listin / photos /" & File.NAME (var.foto [a])) THEN
'it exists, don't copy
    ELSE
        COPY var.foto [a] TO "~ / listin / photos /" & File.NAME (var.foto [a])
    ENDIF
NEXT
'have to modify photos directories and copy data to named “~/listin/data” folder
NewRecPhoto.Resize (var.dni.COUNT)
FOR a = 0 TO var.dni.COUNT - 1
    NewRecPhoto [a] = "~ / listin / photos /" & File.NAME (var.foto [a])
NEXT

'create a “ListeGenerale.lis” file, wich contents will be all accessible data from “~/listin ”folder
target = "~ / listin / GeneralList.lis"
EndOfLine = "|"
sLine = "v0.0.1" & Endofline 'version information
sLine & = "listin.20100718" & Endofline ' program with which was created this file
sLine & = var.id.COUNT & Endofline 'existing records count

FOR
a = 0 TO var.id.COUNT - 1
    sLine &= var.id[a] & Endofline
    sLine &= var.dni[a] & Endofline
    sLine &= var.name[a] & Endofline
    sLine &= var.surname[a] & Endofline
    sLine &= var.company[a] & Endofline
    sLine &= var.position[a] & Endofline
    sLine &= var.tel_company[a] & Endofline
    sLine &= var.tel_private[a] & Endofline
    sLine &= var.fax[a] & Endofline
    sLine &= var.mobile_company[a] & Endofline
    sLine &= var.mobile_private[a] & Endofline
    sLine &= var.page[a] & Endofline 
'Here we put new photos folder
    sLine &= NewRecPhoto[a] & Endofline 
'replace path to original photo by new one's
    var.photo[a] = NewRecPhoto[a]
    sLine &= var.Address[a] & Endofline
    sLine &= var.comments[a] & Endofline
    sLine &= var.data_date[a] & Endofline
    sLine &= var.mail[a] & Endofline
NEXT
File.Save (target, sLine)
'End of the process
END

Now all the information (images, thumbnails, data) are in  " ~ listin / user.home/ listin." . This directory could be copied to another computer, and paste into your user.home, providing complete available information .